using System.Collections.Generic;
using System.Linq;

namespace PokerStar.Core.Rules
{
    public abstract class BasicRule : IRule
    {
        protected BasicRule(IRule next)
        {
            Next = next;
        }

        public IRule Next { get; private set; }
        public GameResult Test(RuleContext context)
        {
            var rs = Match(context);
            if (rs != null)
                return rs;

            if (Next != null)
                return Next.Test(context);
            return null;
        }

        /// <summary>
        /// Tests if the given cards match the current rule
        ///     and returns an instance of GameResult which stores
        ///     evidence of result
        /// 
        /// Could return null if the cards don't match the rule
        /// </summary>
        protected abstract GameResult Match(RuleContext context);
    }
}